#delimit ;
set more off;
pause on;
clear;
capture log close;

/*****************************************************************************/
/* ABOUT THIS FILE */
/*****************************************************************************/

/*
OVERVIEW
The commands in this file replicate all the tables and figures in the manuscript, appendix, and supplimentary materials.
This file uses db.dta stored in a folder below called "dta".
It exports each table to a file saved in a folder below called "table".
These files are in xml, xlsx, csv, or txt format and can be opened in excel.
It exports each figure to a pdf file saved in a folder belwo called "figures".

CONTENTS
PART 1 INITIAL SETUP
	1. Collapse candidate as UOA (N = 246)
	2. Make macros

PART 2 MANUSCRIPT FIGURES AND DATA (CANDIDATE = UOA)
	FIGURE 3: Marginsplot: Impact of viable groups
	FIGURE 4. Appeals by candidates who are members of one viable group
	DATA: Minimum winning coalition test
	FIGURE 6. Fractional polnomial plot

PART 3 APPENDIX TABLES AND FIGURES (CANDIDATE = UOA)
	TABLE A1. Summary Statistics DV (N = 246)
	TABLE A2. Summary Statistics IVS (N = 246)
	TABLE A3. Summary Statistics IVS (N = 246)
	TABLE A4: Impact of viable groups on ethnic bonding bridging and bypassing
	TABLE A5: OLS Excludes independent and control variables (N = 246)
	TABLE A6: OLS uses continuous variables for the size of candidate groups
	TABLE A7: OLS Clustering on the electoral district (N = 246)
	TABLE A8: OLS Uses dummy variables for indigenous groups (N = 246)
	TABLE A9: Impact of viable groups (includes Islamic party control var)
	TABLE A10: Logit. If ethnic appeal is 50% or more of candidate's posters = 1, else = 0
	TABLE A11: Logit. If ethnic appeal not present in any of a candidates posters = 0, else = 1
	TABLE A12: Ordered logit regression (N = 246)
	TABLE A13: Tobit regression (N = 246)
	FIGURE A1: Marginsplot: Impact of Viable Groups - Continueous IVs
	FIGURE A2. Fractional polnomial plot with Fractionalization index
	FIGURE A3. Fractional polnomial plot with polarization index

PART 4 DATA AND TABLES USING THE POSTERS (N=1,501) AS UOA
	DATA: Party symbolism discussed in manuscript
	TABLE A14. Logit. Election poster = UOA (N = 1,501)
	TABLE A15. MLM Election poster as UOA (N = 1,501) candidate and constituency as levels
	TABLE A16. Number of Posters, Candidates, and Constituencies
*/

/******************************************************************************/
/******************************************************************************/
                         /* PART 1 INITIAL SETUP */
/******************************************************************************/
/******************************************************************************/

/******************************************************************************/
/* 1. Collapse candidate as UOA (N = 246) */
/******************************************************************************/

use "dta/db.dta";

collapse
(mean)
sa_rel re_rel recr_rel non_rel sa_eth re_eth recr_eth non_eth // DVs

(first)
pos_id reg_id // Indexing IDs
h_rgrp_viable h_egrp_viable size_h_rgrp_nonislam0 // IVs
eth_law pl_worship_1000_cangrp poverty farm_grdp_pct num_teams // IVs
female_can pop_log // CVs
dis_code prov_no // Constituency Vars
islam_pop bps_pct_egrp1 efi rfi epi rpi // Demographic Vars
h_rgrp h_egrp h_bps_code_egrp size_h_egrp size_h_rgrp // Candidate Identity
can_d_bond can_i_bond can_r_bond can_d_bridge can_d_maj // Candidate Types
parties one_party party_regh_is party_regh_isonly party_regh_natonly party_regh_natiscoal party_regh_ind, // Parties
by (can_id);

/* Label DVs */
label variable sa_rel "Religious bonding";
label variable sa_eth "Indigenous bonding";
label variable recr_rel "Religious bridging";
label variable recr_eth "Indigenous bridging";
label variable non_rel "Non-religious";
label variable non_eth "Non-indigenous";

/* Label IVs */
label variable h_rgrp_viable "Viable religious group";
label variable h_egrp_viable "Viable indigenous group";
label variable size_h_egrp "Viable candidate ethnic grp %";
label variable size_h_rgrp_nonislam0 "Viable candidate religious grp %";
label variable eth_law "Indigenous law";
label variable pl_worship_1000_cangrp "Places of worship";
label variable poverty "Poverty";
label variable farm_grdp_pct "Fishing/farming GRDP";
label variable num_teams "Number of candidates";

/* Label CVs */
label variable female_can "Female candidate";
label variable pop_log "Population (log)";

/* Label Candidate Types */
label variable can_d_bond "Dual-Bonding candidate";
label variable can_i_bond "Indigenous-Bonding candidate";
label variable can_r_bond "Religious-Bonding candidate";
label variable can_d_bridge "Dual-Bridging candidate";

/* Demographics */
label variable islam_pop "Muslim pop. %";
label variable bps_pct_egrp1 "Largest indigenous grp. %";

/* Party Support */
label variable party_regh_is "Islamic party support";

/******************************************************************************/
/* 2. Make macros */
/******************************************************************************/

local ivars
	 h_egrp_viable h_rgrp_viable;

local altex
	eth_law pl_worship_1000_cangrp poverty farm_grdp_pct num_teams;

local cvars
	female_can pop_log;

local marginsplot_opts
	recast(bar)
	yscale(range(-10 100) noline)
	ylabel(-10(10)100, labsize(3))
	title("")
	level(95)
	plot1opts(barwidth(.75) bargap(-100) color(none));

local otreg_opt
	bdec(2) sdec(2) rdec(2) symbol(**, *, ^) label;

/******************************************************************************/
/******************************************************************************/
            /* PART 2 MANUSCRIPT FIGURES AND DATA (CANDIDATE = UOA) */
/******************************************************************************/
/******************************************************************************/


/******************************************************************************/
/* FIGURE 3: Marginsplot: Impact of viable groups */
/******************************************************************************/

/* Model 2: Non-Indigenous */
reg non_eth `ivars' `altex' `cvars', robust;
margins, at(h_egrp_viable =(0 1)) vsquish;
marginsplot, `marginsplot_opts'
name(eavoid, replace) title("eavoid");

/* Model 4: Indigenous bridging */
reg recr_eth `ivars' `altex' `cvars', robust;
margins, at(h_egrp_viable =(0 1)) vsquish;
marginsplot, `marginsplot_opts'
name(ebridge, replace) title("ebridge");

/* Model 6: Indigenous bonding */
reg sa_eth `ivars' `altex' `cvars', robust;
margins, at(h_egrp_viable =(0 1)) vsquish;
marginsplot, `marginsplot_opts'
name(ebond, replace) title("ebond");

/* Model 8: Non-Religious */
reg non_rel `ivars' `altex' `cvars', robust;
margins, at(h_rgrp_viable =(0 1)) vsquish;
marginsplot, `marginsplot_opts'
name(ravoid, replace) title("ravoid");

/* Model 10: Religious bridging */
reg recr_rel `ivars' `altex' `cvars', robust;
margins, at(h_rgrp_viable =(0 1)) vsquish;
marginsplot, `marginsplot_opts'
name(rbridge, replace) title("rbridge");

/* Model 12: Religious bonding */
reg sa_rel `ivars' `altex' `cvars', robust;
margins, at(h_rgrp_viable =(0 1)) vsquish;
marginsplot, `marginsplot_opts'
name(rbond, replace) title("rbond");

/* Merge */
local gph_combine_opts
	rows(1)
	imargin(l=0 r=4 b=10 t=5)
	ycommon
	ysize(5)
	xsize(10)
	plotregion(style(none));

graph combine
	ebond ebridge eavoid rbond rbridge ravoid,
	`gph_combine_opts' name(bondbridge, replace)
	title("Bonding Bridging Bypassing (with controls)", size(4));

graph export "figures/fig3.pdf", as(pdf) replace;

/******************************************************************************/
/* FIGURE 4. Appeals by candidates who are members of one viable group */
/******************************************************************************/

/* A. INDIGENOUS APPEALS -----------------------------------------------------*/
putexcel set figures/fig4_data, replace;
putexcel
	B1:H1 = ("A. INDIGENOUS APPEALS")
	I1:O1 = ("B. RELIGIOUS APPEALS"),
merge;
putexcel
	B2:C2 = ("BONDING") D2:E2 = ("BRIDGING") F2:G2 = ("BYPASSING")
	I2:J2 = ("BONDING") K2:L2 = ("BRIDGING") M2:N2 = ("BYPASSING"),
	merge;
putexcel
	B3 = ("Ind. Grp.") C3 = ("Rel. Grp.") D3 = ("Ind. Grp.") E3 = ("Rel. Grp.")  F3 = ("Ind. Grp.") G3 = ("Rel. Grp.")
	I3 = ("Ind. Grp.") J3 = ("Rel. Grp.") K3 = ("Ind. Grp.") L3 = ("Rel. Grp.")  M3 = ("Ind. Grp.") N3 = ("Rel. Grp.");
putexcel
	A4 = ("Diff. in mean")
	A5 = ("t-stat")
	A6 = ("p-value");

ttest sa_eth, by(can_i_bond);
gen tstat = -r(t) if r(t) > 0;					// Change t-stat to opposite sign
replace tstat = abs(r(t)) if r(t) < 0;
putexcel
	B4 = (`r(mu_2)' - `r(mu_1)')					// Difference in mean
	B5 = tstat														// t-statistic
	B6 = `r(p)';													// p-value

ttest sa_eth, by(can_r_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel C4 = (`r(mu_2)' - `r(mu_1)') C5 = tstat C6 = `r(p)';

ttest recr_eth, by(can_i_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel D4 = (`r(mu_2)' - `r(mu_1)') D5 = tstat D6 = `r(p)';

ttest recr_eth, by(can_r_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel E4 = (`r(mu_2)' - `r(mu_1)') E5 = tstat E6 = `r(p)';

ttest non_eth, by(can_i_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel F4 = (`r(mu_2)' - `r(mu_1)') F5 = tstat F6 = `r(p)';

ttest non_eth, by(can_r_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel G4 = (`r(mu_2)' - `r(mu_1)') G5 = tstat G6 = `r(p)';

/* B. RELIGIOUS APPEALS ------------------------------------------------------*/
ttest sa_rel, by(can_i_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel I4 = (`r(mu_2)' - `r(mu_1)') I5 = tstat I6 = `r(p)';

ttest sa_rel, by(can_r_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel J4 = (`r(mu_2)' - `r(mu_1)') J5 = tstat J6 = `r(p)';

ttest recr_rel, by(can_i_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel K4 = (`r(mu_2)' - `r(mu_1)') K5 = tstat K6 = `r(p)';

ttest recr_rel, by(can_r_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel L4 = (`r(mu_2)' - `r(mu_1)') L5 = tstat L6 = `r(p)';

ttest non_rel, by(can_i_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel M4 = (`r(mu_2)' - `r(mu_1)') M5 = tstat M6 = `r(p)';

ttest non_rel, by(can_r_bond);
replace tstat = -r(t) if r(t) > 0;
replace tstat = abs(r(t)) if r(t) < 0;
putexcel N4 = (`r(mu_2)' - `r(mu_1)') N5 = tstat N6 = `r(p)';

/******************************************************************************/
/* DATA: Minimum winning coalition test  */
/******************************************************************************/

gen minimum_wc = "ind" if can_d_bond == 1;
replace minimum_wc = "rel" if can_d_bond == 1 & size_h_rgrp < size_h_egrp;

gen sa_min = .;
replace sa_min = sa_rel if minimum_wc == "rel";
replace sa_min = sa_eth if minimum_wc == "ind";

gen sa_max = .;
replace sa_max = sa_rel if minimum_wc == "ind";
replace sa_max = sa_eth if minimum_wc == "rel";

sum sa_min sa_max; // % posters with appeals targeting minimum grp & maximum grp

/* Just using simple majorities (not using viable groups) */
gen minimum_wc2 = "ind" if can_d_maj == 1;
replace minimum_wc2 = "rel" if can_d_maj == 1 & size_h_rgrp < size_h_egrp;

gen sa_min2 = .;
replace sa_min2 = sa_rel if minimum_wc2 == "rel";
replace sa_min2 = sa_eth if minimum_wc2 == "ind";

gen sa_max2 = .;
replace sa_max2 = sa_rel if minimum_wc2 == "ind";
replace sa_max2 = sa_eth if minimum_wc2 == "rel";

sum sa_min2 sa_max2; // % posters with appeals targeting minimum grp & maximum grp

gen sa_min3 = .;
replace sa_min3 = sa_rel if minimum_wc2 == "rel" & h_rgrp != "islam";
gen sa_max3 = .;
replace sa_max3 = sa_eth if minimum_wc2 == "rel" & h_rgrp != "islam";
sum sa_min3 sa_max3;

/******************************************************************************/
/* FIGURE 6. Fractional polnomial plot  */
/******************************************************************************/

local fp_opts
	estcmd(reg)
	level(90)
	yscale(range(-20 100)) ylabel(-20(20)100)
	xscale(range(0 100)) xlabel(0(20)100);

graph twoway fpfitci sa_eth bps_pct_egrp1,
	`fp_opts'
	name(ebond_dis_fp, replace)
	title(Indigenous Bonding, size(3.5));

graph twoway fpfitci recr_eth bps_pct_egrp1,
	`fp_opts'
	name(ebridge_dis_fp, replace)
	title(Indigenous Bridging, size(3.5));

graph twoway fpfitci sa_rel islam_pop,
	`fp_opts'
	name(rbond_dis_fp, replace)
	title(Islamic Bonding, size(3.5));

graph twoway fpfitci recr_rel islam_pop,
	`fp_opts'
	name(rbridge_dis_fp, replace)
	title(Religious Bridging, size(3.5));

/* None */
graph twoway fpfitci non_eth bps_pct_egrp1,
	`fp_opts'
	name(enone_dis_fp, replace)
	title(Ethnic Bypassing, size(3.5));

graph twoway fpfitci non_rel islam_pop,
	`fp_opts'
	name(rnone_dis_fp, replace)
	title(Religious Bypassing, size(3.5));

graph combine
	ebond_dis_fp ebridge_dis_fp enone_dis_fp rbond_dis_fp rbridge_dis_fp rnone_dis_fp,
	`gph_combine_opts' name(bondbridge_dis_fp, replace)
	title("Bonding Bridging Bypassing by Group Size", size(4));

graph export "figures/fig6.pdf", as(pdf) replace;

/******************************************************************************/
/******************************************************************************/
          /* PART 3 APPENDIX TABLES AND FIGURES (CANDIDATE = UOA) */
/******************************************************************************/
/******************************************************************************/

/******************************************************************************/
/* TABLE A1. Summary Statistics DV (N = 246) */
/******************************************************************************/

sum
sa_eth recr_eth non_eth
sa_rel recr_rel non_rel, separator(0) format;

/******************************************************************************/
/* TABLE A2. Summary Statistics IVS (N = 246) */
/******************************************************************************/

sum
h_egrp_viable h_rgrp_viable
eth_law pl_worship_1000_cangrp poverty farm_grdp_pct num_teams
female_can pop_log, separator(0);

/******************************************************************************/
/* TABLE A3. Summary Statistics IVS (N = 246) */
/******************************************************************************/

corr
h_egrp_viable h_rgrp_viable
eth_law pl_worship_1000_cangrp poverty farm_grdp_pct num_teams
female_can pop_log;

/******************************************************************************/
/* TABLE A4: Impact of viable groups on ethnic bonding bridging and bypassing */
/******************************************************************************/

reg sa_eth `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a4, `otreg_opt' title(OLS Model) replace;
reg recr_eth `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a4, `otreg_opt';
reg non_eth `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a4, `otreg_opt';
reg sa_rel `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a4, `otreg_opt';
reg recr_rel `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a4, `otreg_opt';
reg non_rel `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a4, `otreg_opt' excel;
erase tables/table_a4.txt;

/******************************************************************************/
/* TABLE A5: OLS Excludes independent and control variables (N = 246) */
/******************************************************************************/

reg sa_eth `ivars', robust;
outreg2 using tables/table_a5, `otreg_opt' title(OLS Model: Key IVs only) replace;
reg recr_eth `ivars', robust;
outreg2 using tables/table_a5, `otreg_opt';
reg non_eth `ivars', robust;
outreg2 using tables/table_a5, `otreg_opt';
reg sa_rel `ivars', robust;
outreg2 using tables/table_a5, `otreg_opt';
reg recr_rel `ivars', robust;
outreg2 using tables/table_a5, `otreg_opt';
reg non_rel `ivars', robust;
outreg2 using tables/table_a5, `otreg_opt' excel;
erase tables/table_a5.txt;

/******************************************************************************/
/* TABLE A6: OLS uses continuous variables for the size of candidate groups */
/******************************************************************************/

reg sa_eth size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
outreg2 using tables/table_a6, `otreg_opt' title(OLS Model) replace;
reg recr_eth size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
outreg2 using tables/table_a6, `otreg_opt';
reg non_eth size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
outreg2 using tables/table_a6, `otreg_opt';
reg sa_rel size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
outreg2 using tables/table_a6, `otreg_opt';
reg recr_rel size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
outreg2 using tables/table_a6, `otreg_opt';
reg non_rel size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
outreg2 using tables/table_a6, `otreg_opt' excel;
erase tables/table_a6.txt;

/******************************************************************************/
/* TABLE A7: OLS Clustering on the electoral district (N = 246) */
/******************************************************************************/

reg sa_eth `ivars' `altex' `cvars', vce(cluster dis_code);
outreg2 using tables/table_a7, `otreg_opt' title(OLS Model: Clustering on district) replace;
reg recr_eth `ivars' `altex' `cvars', vce(cluster dis_code);
outreg2 using tables/table_a7, `otreg_opt';
reg non_eth `ivars' `altex' `cvars', vce(cluster dis_code);
outreg2 using tables/table_a7, `otreg_opt';
reg sa_rel `ivars' `altex' `cvars', vce(cluster dis_code);
outreg2 using tables/table_a7, `otreg_opt';
reg recr_rel `ivars' `altex' `cvars', vce(cluster dis_code);
outreg2 using tables/table_a7, `otreg_opt';
reg non_rel `ivars' `altex' `cvars', vce(cluster dis_code);
outreg2 using tables/table_a7, `otreg_opt' excel;
erase tables/table_a7.txt;

/******************************************************************************/
/* TABLE A8: OLS Uses dummy variables for indigenous groups (N = 246) */
/******************************************************************************/

reg sa_eth `ivars' `altex' `cvars' i.h_bps_code_egrp, robust;
outreg2 using tables/table_a8, `otreg_opt' title(OLS Fixed Effects Model) replace;
reg recr_eth `ivars' `altex' `cvars' i.h_bps_code_egrp, robust;
outreg2 using tables/table_a8, `otreg_opt';
reg non_eth `ivars' `altex' `cvars' i.h_bps_code_egrp, robust;
outreg2 using tables/table_a8, `otreg_opt';
reg sa_rel `ivars' `altex' `cvars' i.h_bps_code_egrp, robust;
outreg2 using tables/table_a8, `otreg_opt';
reg recr_rel `ivars' `altex' `cvars' i.h_bps_code_egrp, robust;
outreg2 using tables/table_a8, `otreg_opt';
reg non_rel `ivars' `altex' `cvars' i.h_bps_code_egrp, robust;
outreg2 using tables/table_a8, `otreg_opt' excel;
erase tables/table_a8.txt;

/******************************************************************************/
/* TABLE A9: Impact of viable groups (includes Islamic party control var) */
/******************************************************************************/

/* Counting candidates with party support */
count; // total number of candidates
count if parties == ""; // candidates with no party information
count if parties == "independent"; // independent candidates
count if one_party == 1;

tab party_regh_isonly;
tab party_regh_natonly;
tab party_regh_natiscoal;
tab party_regh_ind;

reg sa_eth `ivars' party_regh_is `altex' `cvars', robust;
outreg2 using tables/table_a9, `otreg_opt' title(OLS Model) replace;
reg recr_eth `ivars' party_regh_is `altex' `cvars', robust;
outreg2 using tables/table_a9, `otreg_opt';
reg non_eth `ivars' party_regh_is `altex' `cvars', robust;
outreg2 using tables/table_a9, `otreg_opt';
reg sa_rel `ivars' party_regh_is `altex' `cvars', robust;
outreg2 using tables/table_a9, `otreg_opt';
reg recr_rel `ivars' party_regh_is `altex' `cvars', robust;
outreg2 using tables/table_a9, `otreg_opt';
reg non_rel `ivars' party_regh_is `altex' `cvars', robust;
outreg2 using tables/table_a9, `otreg_opt' excel;
erase tables/table_a9.txt;

/******************************************************************************/
/* TABLE A10: Logit. If ethnic appeal is 50% or more of candidate's posters = 1, else = 0 */
/******************************************************************************/

gen sa_eth_b = (sa_eth>=50);
gen recr_eth_b = (recr_eth>=50);
gen non_eth_b = (non_eth>=50);
gen sa_rel_b = (sa_rel>=50);
gen recr_rel_b = (recr_rel>=50);
gen non_rel_b = (non_rel>=50);

logit sa_eth_b `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a10, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2)
title(Logit Model 1: DV = 1 if ethnic appeal is 50% or more posters) replace;
logit recr_eth_b `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a10, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit non_eth_b `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a10, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit sa_rel_b `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a10, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit recr_rel_b `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a10, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit non_rel_b `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a10, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2) excel;
erase tables/table_a10.txt;

/******************************************************************************/
/* TABLE A11: Logit. If ethnic appeal not present in any of a candidates posters = 0, else = 1 */
/******************************************************************************/
gen sa_eth_b2 = (sa_eth>0);
gen recr_eth_b2 = (recr_eth>0);
gen non_eth_b2 = (non_eth>0);
gen sa_rel_b2 = (sa_rel>0);
gen recr_rel_b2 = (recr_rel>0);
gen non_rel_b2 = (non_rel>0);

logit sa_eth_b2 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a11, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2)
title(Logit Model 2: DV = 0 if ethnic appeal is not present in any posters) replace;
logit recr_eth_b2 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a11, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit non_eth_b2 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a11, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit sa_rel_b2 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a11, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit recr_rel_b2 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a11, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit non_rel_b2 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a11, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2) excel;
erase tables/table_a11.txt;

/******************************************************************************/
/* TABLE A12: Ordered logit regression (N = 246) */
/******************************************************************************/

/* DV = 1 if there is no poster with the ethnic appeal; DV = 2 if any but not all
posters have the ethnic appeal; DV = 3 if all posters have the ethnic appeal.*/

gen sa_eth_b3 = 0;
replace sa_eth_b3 = 1 if sa_eth  == 0;
replace sa_eth_b3 = 2 if sa_eth  > 0;
replace sa_eth_b3 = 3 if sa_eth  == 100;

gen recr_eth_b3 = 0;
replace recr_eth_b3 = 1 if recr_eth == 0;
replace recr_eth_b3 = 2 if recr_eth > 0;
replace recr_eth_b3 = 3 if recr_eth == 100;

gen non_eth_b3 = 0;
replace non_eth_b3 = 1 if non_eth  == 0;
replace non_eth_b3 = 2 if non_eth  > 0;
replace non_eth_b3 = 3 if non_eth  == 100;

gen sa_rel_b3 = 0;
replace sa_rel_b3 = 1 if sa_rel == 0;
replace sa_rel_b3 = 2 if sa_rel > 0;
replace sa_rel_b3 = 3 if sa_rel == 100;

gen recr_rel_b3 = 0;
replace recr_rel_b3 = 1 if recr_rel == 0;
replace recr_rel_b3 = 2 if recr_rel > 0;
replace recr_rel_b3 = 3 if recr_rel == 100;

gen non_rel_b3 = 0;
replace non_rel_b3 = 1 if non_rel == 0;
replace non_rel_b3 = 2 if non_rel > 0;
replace non_rel_b3 = 3 if non_rel == 100;

ologit sa_eth_b3 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a12, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2)
title(Ordered Logit Model: DV = 1 none 2 any 3 all) replace;
ologit recr_eth_b3 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a12, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
ologit non_eth_b3 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a12, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
ologit sa_rel_b3 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a12, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
ologit recr_rel_b3 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a12, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
ologit non_rel_b3 `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a12, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2) excel;
erase tables/table_a12.txt;

/******************************************************************************/
/* TABLE A13: Tobit regression (N = 246) */
/******************************************************************************/
/* Lower limit (ie. left-censoring) set to 0;
upper limit (ie. right-censoring) set to 100 for each DV. */

tobit sa_eth `ivars' `altex' `cvars', ll(0) ul(100);
outreg2 using tables/table_a13, `otreg_opt' title(Tobit Model) replace;
tobit recr_eth `ivars' `altex' `cvars', ll(0) ul(100);
outreg2 using tables/table_a13, `otreg_opt';
tobit non_eth `ivars' `altex' `cvars', ll(0) ul(100);
outreg2 using tables/table_a13, `otreg_opt';
tobit sa_rel `ivars' `altex' `cvars', ll(0) ul(100);
outreg2 using tables/table_a13, `otreg_opt';
tobit recr_rel `ivars' `altex' `cvars', ll(0) ul(100);
outreg2 using tables/table_a13, `otreg_opt';
tobit non_rel `ivars' `altex' `cvars', ll(0) ul(100);
outreg2 using tables/table_a13, `otreg_opt' excel;
erase tables/table_a13.txt;

/******************************************************************************/
/* FIGURE A1: Marginsplot: Impact of Viable Groups - Continueous IVs */
/******************************************************************************/

/* Model 2: Non-Indigenous */
reg non_eth size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
margins, at(size_h_egrp =(0(10)100)) vsquish;
marginsplot, `marginsplot_opts'
name(eavoid2, replace) title("eavoid2");

/* Model 4: Indigenous bridging */
reg recr_eth size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
margins, at(size_h_egrp =(0(10)100)) vsquish;
marginsplot, `marginsplot_opts'
name(ebridge2, replace) title("ebridge2");

/* Model 6: Indigenous bonding */
reg sa_eth size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
margins, at(size_h_egrp =(0(10)100)) vsquish;
marginsplot, `marginsplot_opts'
name(ebond2, replace) title("ebond2");

/* Model 8: Non-Religious */
reg non_rel size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
margins, at( size_h_rgrp_nonislam0 =(0(10)100)) vsquish;
marginsplot, `marginsplot_opts'
name(ravoid2, replace) title("ravoid2");

/* Model 10: Religious bridging */
reg recr_rel size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
margins, at( size_h_rgrp_nonislam0 =(0(10)100)) vsquish;
marginsplot, `marginsplot_opts'
name(rbridge2, replace) title("rbridge2");

/* Model 12: Religious bonding */
reg sa_rel size_h_egrp size_h_rgrp_nonislam0 `altex' `cvars', robust;
margins, at( size_h_rgrp_nonislam0 =(0(10)100)) vsquish;
marginsplot, `marginsplot_opts'
name(rbond2, replace) title("rbond2");

/* Merge */
local gph_combine_opts
	rows(1)
	imargin(l=0 r=4 b=10 t=5)
	ycommon
	ysize(5)
	xsize(10)
	plotregion(style(none));

graph combine
	ebond2 ebridge2 eavoid2 rbond2 rbridge2 ravoid2,
	`gph_combine_opts' name(bondbridge2, replace)
	title("Bonding Bridging Bypassing with controls and cont. IVs", size(4));

graph export "figures/fig_a1.pdf", as(pdf) replace;

/******************************************************************************/
/* FIGURE A2. Fractional polnomial plot with Fractionalization index  */
/******************************************************************************/

local fp_opts
	estcmd(reg)
	level(90)
	yscale(range(-20 100)) ylabel(-20(20)100, labsize(3))
	xscale(range(0 1)) xlabel(0(0.1)1);

graph twoway fpfitci sa_eth efi,
	`fp_opts'
	name(ebond_dis_fp_f, replace)
	title(A. Indigenous Bonding, size(3.5));

graph twoway fpfitci recr_eth efi,
	`fp_opts'
	name(ebridge_dis_fp_f, replace)
	title(B. Indigenous Bridging, size(3.5));

graph twoway fpfitci sa_rel rfi,
	`fp_opts'
	name(rbond_dis_fp_f, replace)
	title(C. Religious Bonding, size(3.5));

graph twoway fpfitci recr_rel rfi,
	`fp_opts'
	name(rbridge_dis_fp_f, replace)
	title(D. Religious Bridging, size(3.5));

/* None */
graph twoway fpfitci non_eth efi,
	`fp_opts'
	name(enone_dis_fp_f, replace)
	title(E. Ethnic Bypassing, size(3.5));

graph twoway fpfitci non_rel rfi,
	`fp_opts'
	name(rnone_dis_fp_f, replace)
	title(F. Religious Bypassing, size(3.5));

/* Combine */
graph combine
	ebond_dis_fp_f ebridge_dis_fp_f enone_dis_fp_f rbond_dis_fp_f rbridge_dis_fp_f rnone_dis_fp_f,
	`gph_combine_opts' name(bondbridge_dis_fp_f, replace)
	title("Bonding Bridging Bypassing by Fractionalization Index", size(4));

graph export "figures/fig_a2.pdf", as(pdf) replace;

/******************************************************************************/
/* FIGURE A3. Fractional polnomial plot with polarization index  */
/******************************************************************************/

/* epi rpi  ethnic pol. index			rel pol. index (Reynol-Querol’s (2002) */

graph twoway fpfitci sa_eth epi,
	`fp_opts'
	name(ebond_dis_fp_p, replace)
	title(A. Indigenous Bonding, size(3.5));

graph twoway fpfitci recr_eth epi,
	`fp_opts'
	name(ebridge_dis_fp_p, replace)
	title(B. Indigenous Bridging, size(3.5));

graph twoway fpfitci sa_rel rpi,
	`fp_opts'
	name(rbond_dis_fp_p, replace)
	title(C. Religious Bonding, size(3.5));

graph twoway fpfitci recr_rel rpi,
	`fp_opts'
	name(rbridge_dis_fp_p, replace)
	title(D. Religious Bridging, size(3.5));

/* None */
graph twoway fpfitci non_eth epi,
	`fp_opts'
	name(enone_dis_fp_p, replace)
	title(E. Ethnic Bypassing, size(3.5));

graph twoway fpfitci non_rel rpi,
	`fp_opts'
	name(rnone_dis_fp_p, replace)
	title(F. Religious Bypassing, size(3.5));

/* Combine */
graph combine
	ebond_dis_fp_p ebridge_dis_fp_p enone_dis_fp_p rbond_dis_fp_p rbridge_dis_fp_p rnone_dis_fp_p,
	`gph_combine_opts' name(bondbridge_dis_fp_p, replace)
	title("Bonding Bridging Bypassing by Polarization Index", size(4));

graph export "figures/fig_a3.pdf", as(pdf) replace;
clear;



/******************************************************************************/
/******************************************************************************/
         /* PART 4 DATA AND TABLES USING THE POSTERS (N=1,501) AS UOA */
/******************************************************************************/
/******************************************************************************/

use "dta/db.dta";

/******************************************************************************/
/* DATA: Party symbolism discussed in manuscript */
/******************************************************************************/

tab clothing1;
tab clothing2;
tab clothing1_party;
tab clothing2_party;
tab partysup;
tab bgpartylogo;
tab party_elites;

gen party_symbolism = 0;
replace party_symbolism = 1 if clothing1_party == "yes";
replace party_symbolism = 1 if clothing2_party == "yes";
replace party_symbolism = 1 if partysup == "prominent";
replace party_symbolism = 1 if partysup == "discrete";
replace party_symbolism = 1 if bgpartylogo == "yes";
replace party_symbolism = 1 if party_elites == 1;

tab party_symbolism;

/******************************************************************************/
/* TABLE A14. Logit. Election poster = UOA (N = 1,501) */
/******************************************************************************/

/* Label DVs */
label variable sa_rel "Religious bonding";
label variable sa_eth "Indigenous bonding";
label variable recr_rel "Religious bridging";
label variable recr_eth "Indigenous bridging";
label variable non_rel "Non-religious";
label variable non_eth "Non-indigenous";

/* Label IVs */
label variable h_rgrp_viable "Viable religious group";
label variable h_egrp_viable "Viable indigenous group";
label variable eth_law "Indigenous law";
label variable pl_worship_1000_cangrp "Places of worship";
label variable poverty "Poverty";
label variable farm_grdp_pct "Fishing/farming GRDP";
label variable num_teams "Number of candidates";
label variable female_can "Female Candidate";
label variable pop_log "Population (log)";

logit sa_eth `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a14, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2)
title(Logit Model poster as UOA) replace;
logit recr_eth `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a14, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit non_eth `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a14, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit sa_rel `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a14, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit recr_rel `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a14, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2);
logit non_rel `ivars' `altex' `cvars', robust;
outreg2 using tables/table_a14, `otreg_opt' e(ll) addstat(Pseudo R-squared, `e(r2_p)') adec(2) excel;
erase tables/table_a14.txt;

/******************************************************************************/
/* TABLE A15. MLM Election poster as UOA (N = 1,501) candidate and constituency as levels. */
/******************************************************************************/

melogit sa_eth `ivars' `altex' `cvars' || can_id:;
outreg2 using tables/table_a15, `otreg_opt' e(ll) adec(2) title(Logit Model poster as UOA) replace;
melogit recr_eth `ivars' `altex' `cvars' || can_id:;
outreg2 using tables/table_a15, `otreg_opt' e(ll) adec(2);
melogit non_eth `ivars' `altex' `cvars' || can_id:;
outreg2 using tables/table_a15, `otreg_opt' e(ll) adec(2);
melogit sa_rel `ivars' `altex' `cvars' || can_id:;
outreg2 using tables/table_a15, `otreg_opt' e(ll) adec(2);
melogit recr_rel `ivars' `altex' `cvars' || can_id:;
outreg2 using tables/table_a15, `otreg_opt' e(ll) adec(2);
melogit non_rel `ivars' `altex' `cvars' || can_id:;
outreg2 using tables/table_a15, `otreg_opt' e(ll) adec(2) excel;
erase tables/table_a15.txt;

/******************************************************************************/
/* TABLE A16. Number of Posters, Candidates, and Constituencies	*/
/******************************************************************************/

bysort pos_id: gen unique_pos = _n;
bysort can_id: gen unique_can = _n;
bysort reg_id: gen unique_reg = _n;

lab def labels_prov_eng
1100 "Aceh"
1200 "North Sumatra"
1300 "West Sumatra"
1400 "Riau"
1500 "Jambi"
1600 "South Sumatra"
1700 "Bengkulu"
1800 "Lampung"
1900 "Babel"
2100 "Kepri"
3100 "Jakarta"
3200 "Java West"
3300 "Java Central"
3400 "Yogyakarta"
3500 "Java East"
3600 "Banten"
5100 "Bali"
5200 "West Nusa Tenggara"
5300 "East Nusa Tenggara"
6100 "West Kalimantan"
6200 "Central Kalimantan"
6300 "South Kalimantan"
6400 "East Kalimantan"
7100 "North Sulawesi"
7200 "Central Sulawesi"
7300 "South Sulawesi"
7400 "Southeast Sulawesi"
7500 "Gorontalo"
7600 "West Sulawesi"
8100 "Maluku"
8200 "North Maluku"
9100 "West Papua"
9400 "Papua", modify;
label values prov_no labels_prov_eng;

tab prov_no;				    // Province Names
tab prov_no, nolabel;		// Province Numbers

/* Distribution of posters, candidates, and electoral districts by province --*/
sort prov_no;
putexcel set "tables/table_a16", replace;
putexcel
	B1:D1 = ("Regional Head Elections"),
	merge;
putexcel
	A2 = ("Province Number")
	B2 = ("Posters")
	C2 = ("Candidates")
	D2 = ("Districts"),
	txtwrap;
tab prov_no, nolabel matcell(freq) matrow(names);
putexcel A3 = matrix(names);
tab prov_no if unique_pos == 1, matcell(freq);
putexcel B3 = matrix(freq);
tab prov_no if unique_can == 1, matcell(freq);
putexcel C3 = matrix(freq);
tab prov_no if unique_reg == 1, matcell(freq);
putexcel D3 = matrix(freq);

/* END OF FILE ****************************************************************/
